package com.example.appointment.model;

import org.litepal.annotation.Column;
import org.litepal.crud.DataSupport;

import java.util.Arrays;

/**
 * 數據庫案例,
 * Created by hehe on 2016/8/31.
 */
public class Example extends DataSupport {

//    Album album = new Album();
//    album.setName("album");
//    album.setPrice(10.99f);
//    album.setCover(getCoverImageBytes());
//    album.save();
    //數據的存儲
//    Song song1 = new Song();
//    song1.setName("song1");
//    song1.setDuration(320);
//    song1.setAlbum(album);
//    song1.save();
//    Song song2 = new Song();
//    song2.setName("song2");;
//    song2.setDuration(356);
//    song2.setAlbum(album);
//    song2.save();
//    listbaocun
//    DataSupport.saveAll(cityVO.getCities());
//    DataSupport.saveAll(cityVO.getDistricts());
//    DataSupport.saveAll(cityVO.getProvinces());


    //数据的更新
//Album albumToUpdate = DataSupport.find(Album.class, 1);
//    albumToUpdate.setPrice(20.99f); // raise the price
//    albumToUpdate.save();

    /**
     * 更新指定的id的數據
     *Album albumToUpdate = new Album();
     albumToUpdate.setPrice(20.99f); // raise the price
     albumToUpdate.update(id);
     */
    /**
     * 更新所有的指定的條件的數據
     * Album albumToUpdate = new Album();
     albumToUpdate.setPrice(20.99f); // raise the price
     albumToUpdate.updateAll("name = ?", "album");
     */
/**
 * 删除单个数据（根据指定的id）
 * DataSupport.delete(Song.class, id);
 *
 */

/**
 * 刪除所有满足条件的數據
 *DataSupport.deleteAll(Song.class, "duration > ?" , "350");
 */


    /**
     * 根据单个id来查找对应的数据
     * Song song = DataSupport.find(Song.class, id);
     */

    /**
     * 查找所有的數據
     * List<Song> allSongs = DataSupport.findAll(Song.class);
     */
/**
 * 根具條件來查詢對應的數據
 * List<Song> songs = DataSupport.where("name like ?", "song%").order("duration").find(Song.class);
 */


    /**
     * 如果你想修改表的列的屬性,隨便改，然後把assests文件里面的litepal.xml文件裏面的version+1
     * Add a field which annotated as unique = true.
     * Change a field's annoation into unique = true.
     * Change a field's annoation into nullable = false.
     */

    @Column(unique = true, defaultValue = "unknown")
    private String name;

    private float price;

    private byte[] cover;

//    private List<Example2> songs = new ArrayList<Example2>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public byte[] getCover() {
        return cover;
    }

    public void setCover(byte[] cover) {
        this.cover = cover;
    }

    @Override
    public String toString() {
        return "Example{" +
                "name='" + name + '\'' +
                ", price=" + price +
                ", cover=" + Arrays.toString(cover) +
                '}';
    }
}
